Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces selective feature flag evaluation optimization to the PostHog Python SDK. The key change adds a flag_keys_to_evaluate parameter to all feature flag evaluation methods (get_flags_decision(), get_all_flags(), get_all_flags_and_payloads(), get_feature_variants(), get_feature_payloads(), and get_feature_flags_and_payloads()). This parameter allows clients to specify exactly which feature flags they want to evaluate instead of evaluating all available flags.
The implementation adds a flag_keys_filter option to the send_feature_flags parameter in capture events, enabling selective flag evaluation during event tracking. The optimization works at two levels: for remote evaluation, it passes the specified flag keys to the /flags endpoint to reduce server-side processing and network overhead; for local evaluation, it filters the flag processing to only evaluate the requested flags.
The change also optimizes single flag evaluation by making _get_feature_flag_details_from_decide request only the specific flag being evaluated rather than all flags. This addresses performance concerns for applications with many feature flags where only a subset needs evaluation. The implementation maintains backward compatibility by making the parameter optional with a default of None, preserving existing behavior when not specified.
Confidence score: 4/5
- This PR is generally safe to merge but requires careful review of the parameter passing logic
- Score reflects well-structured implementation with comprehensive tests, but the complex parameter threading across multiple methods introduces potential for subtle bugs
- Pay close attention to
posthog/client.pyfor proper parameter handling and the test files for coverage validation
6 files reviewed, no comments
|
I was a little confused by |
It's part of the |
flag_keys_to_evaluateparameter to all relevant feature flag methods:flag_keys_filteroption to thesend_feature_flagsparameter in capture events, allowing selective flag evaluationflag_keys_to_evaluatewhen provided_get_feature_flag_details_from_flags) to only request the specific flag being evaluatedContext: https://posthog.slack.com/archives/C06UTAJJEHM/p1755274454897179